package com.xbs.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.LimitEntity;
import com.xbs.service.content.LimitAdminService;
@WebServlet("/ajaxlimit")
public class AjaxLimitManageAdminServlet extends BaseServlet {
	//服务层
	private LimitAdminService ls;
	//权限id对象集合
	private List<LimitEntity> lelst;
	//角色id
	private Integer rid=0;
	public AjaxLimitManageAdminServlet() {
		ls = new LimitAdminService();
		lelst = new ArrayList<LimitEntity>();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取用户选择的角色
		String role="";
		if(req.getParameter("role")!=null&&req.getParameter("role").length()!=0){
			role = req.getParameter("role");
		}
		
		//根据角色查找角色id
		rid = ls.selRoleId(role);
		//根据角色id查找该用户所拥有的权限
		lelst = ls.selLimit(rid);
	
		//字符串拼接
		String str="";
		if(lelst.size()!=0&&lelst!=null){
			for(int i =0;i<lelst.size();i++){
				str+=lelst.get(i).getLimitid()+",";
			}
			str=str.substring(0,str.length()-1);
		}
		
		resp.getWriter().print(str);
		
	}
}
